<template>
	<view class='pics'>
		<!-- 左侧图片 -->
		<scroll-view class="left" scroll-y>
			<view 
			@click="leftClickHandle(index)"
			:class="active==index?'active':''" 
			v-for='(item, index) in cates' 
			:key='item.id'>
				第 {{index+1}} 页
			</view>
		</scroll-view>
		
		<!-- 右侧图片 -->
		<scroll-view class="right" scroll-y>
			<view class='item' v-for='item in secondData' :key='item.id'>
				<image @click="previewImg(item.host_image)" :src='item.host_image'></image>
				<text>
					商品id: {{item.id}}<br> 
					商品名: {{item.goods_name}} <br> 
					价格:{{item.present_price}}/{{item.original_price}} 
				</text>
			</view>
			<text v-if='secondData.length == 0'>暂无数据</text>
		</scroll-view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 0,
				cates: [],
				active: 0,
				secondData: [],
			}
		},
		
		methods: {
			async getPicsCate(){
				var page = this.page + 1 // 新一页的数据
				
				const res = await this.$myRequest({
					url: '/api/store/goods?ret_all=1'
				})
				console.log(res)
				this.cates = res.data
				this.leftClickHandle(this.active)
			},
			async leftClickHandle(index){
				this.active = index
				
				// 得到右侧数据
				var page = index + 1
				const res = await this.$myRequest({
					url: '/api/store/goods?page=' + page
				})
				var data = this.add_hostname_before_keyname(res.data, 'image')
				this.secondData = data
			},
			previewImg(current){
				var urls = this.get_keyname_value(this.secondData, 'host_image')
				
				uni.previewImage({
					current: current,
					urls: urls,
				})
			}
			
		},
		onLoad() {
			this.getPicsCate()
		},
	}
</script>

<style lang='scss'>
	page{
		height: 100%;
	}
	.pics{
		height: 100%;
		display: flex;
	}
	.left{
		width: 200rpx;
		height: 100%;
		border-right: 1px solid #EEEEEE;
		view{
			height: 60px;
			line-height: 60px;
			color: #333;
			text-align: center;
			font-size: 30rpx;
			border-top: 1px solid #EEEEEE;
		}
		.active{
			background: $shop-color;
			color: #FFFFFF;
		}
	}
	.right{
		height: 100%;
		width: 520rpx;
		margin: 10rpx auto;
		.item{
			image{
				width: 520rpx;
				height: 520rpx;
				border-radius: 5px;
			}
			text{
				font-size: 30rpx;
				line-height: 60rpx;
			}
		}
	}
</style>
